const Sequelize = require('sequelize')
module.exports = function (sequelize, DataTypes) {
  return sequelize.define(
    'edu_chapters',
    {
      id: {
        autoIncrement: true,
        type: DataTypes.INTEGER,
        allowNull: false,
        primaryKey: true
      },
      course_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: '课程ID',
        references: {
          model: 'edu_courses',
          key: 'id'
        }
      },
      chapterName: {
        type: DataTypes.STRING(10),
        allowNull: false,
        comment: '章节名称'
      },
      description: {
        type: DataTypes.STRING(100),
        allowNull: true,
        comment: '章节描述'
      },
      status: {
        type: DataTypes.TINYINT,
        allowNull: false,
        defaultValue: 1,
        comment: '0:隐藏 1:待更新 2:已发布'
      },
      sort: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: '排序字段'
      }
    },
    {
      sequelize,
      tableName: 'edu_chapters',
      timestamps: true,
      indexes: [
        {
          name: 'PRIMARY',
          unique: true,
          using: 'BTREE',
          fields: [{ name: 'id' }]
        },
        {
          name: 'course_id',
          using: 'BTREE',
          fields: [{ name: 'course_id' }]
        }
      ]
    }
  )
}
